//
//  ViewController.m
//  责任链模式
//
//  Created by flannery on 2018/12/18.
//  Copyright © 2018年 flannery. All rights reserved.
//

#import "ViewController.h"
#import "AbstractLogger.h"
#import "ErrorLogger.h"
#import "FileLogger.h"
#import "ConsoleLogger.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    AbstractLogger *loggerChain = [self getChainOfLoggers];
    [loggerChain logMessage:_INFO message:@"This is an information."];
    [loggerChain logMessage:_DEBUG message:@"This is an debug level information."];
    [loggerChain logMessage:_ERROR message:@"This is an error information"];
}

-(AbstractLogger*)getChainOfLoggers{
    AbstractLogger *errorLogger = [[ErrorLogger alloc]initWithLevel:_ERROR];
    AbstractLogger *fileLogger  = [[FileLogger alloc] initWithLevel:_DEBUG];
    AbstractLogger *consoleLogger = [[ConsoleLogger alloc] initWithLevel:_INFO];
    
    [errorLogger setNextLoggering:fileLogger];
    [fileLogger setNextLoggering:consoleLogger];
    
    return errorLogger;
}


@end
